#ifndef GAMEROOM_H
#define GAMEROOM_H

#include <QWidget>
#include<QWebSocket>
#include<QPainter>
#include <QMouseEvent>
#include "register.h"

#define SIZE 15
#define WIDTH 20
namespace Ui {
class gameRoom;
}

class gameRoom : public QWidget
{
    Q_OBJECT

public:
    explicit gameRoom(QWidget *parent = nullptr);
    ~gameRoom();

    void ws_room(QString ssid);//在房间建立长连接

    void closeEvent(QCloseEvent *event);//退出页面事件函数

    const int x=160,y=100;

    void paintEvent(QPaintEvent*);

    void mousePressEvent(QMouseEvent *event);

    void put_chess(bool me);//判断该谁走棋

    void sendChess(int row, int col);//发送走棋信息

private slots:
    void connectHandle();

    void disConnectHandle();

    //void errorHandle(QAbstractSocket::SocketError error);

    void recvMessageHandle(const QString& msg);

    void on_pushButton_return_gameHall_clicked();

    void on_pushButton_send_clicked();

private:
    Ui::gameRoom *ui;

    QWebSocket* ws;//长连接
    QJsonObject room_info;//房间信息
    bool is_me;//判断谁先走棋
    int color_id;//判断谁是黑棋，谁是白棋
    int chess_board[SIZE + 1][SIZE + 1] = { 0 };
    QPainter* paint;//设置画家
    int row;//下棋的坐标
    int col;
    QString _ssid;//session id
    QString text;//保存历史消息
};

#endif // GAMEROOM_H
